package website.lucaswork.survey.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.caucho.HessianServiceExporter;
import website.lucaswork.survey.core.hessian.SurveyCustomSerializerFactory;
import website.lucaswork.survey.core.services.SurveyService;
import website.lucaswork.survey.core.services.UserService;

@Configuration
public class HessianConfiguration {
    @Autowired
    UserService userService;

    @Autowired
    SurveyService surveyService;

    @Autowired
    SurveyCustomSerializerFactory surveyCustomSerializerFactory;

    @Bean(name = "/user.invoker")
    HessianServiceExporter userExporter() {
        HessianServiceExporter exporter = new HessianServiceExporter();
        exporter.setService(userService);
        exporter.setServiceInterface(UserService.class);
        exporter.setSerializerFactory(surveyCustomSerializerFactory);
        return exporter;
    }

    @Bean(name = "/survey.invoker")
    HessianServiceExporter surveyExporter() {
        HessianServiceExporter exporter = new HessianServiceExporter();
        exporter.setService(surveyService);
        exporter.setServiceInterface(SurveyService.class);
        return exporter;
    }
}
